<?php
	
	if (!class_exists('ctl_member'))
	{
		require_once(CORE_DIR.'/shop/controller/ctl.member.php');
	}
	class collocate_goods_member_ctl extends ctl_member
	{
		function collocate_goods_member_ctl()
		{
			parent::ctl_member();
		}

		function _output()
		{
			if($GLOBALS['runtime']['member_lv']){
				$oLevel = &$this->system->loadModel('member/level');
				$aLevel = $oLevel->getFieldById($GLOBALS['runtime']['member_lv']);
				if($aLevel['disabled']=='false'){
					$this->member['levelname'] = $aLevel['name'];
				}
			}

			$oSex = &$this->system->loadModel('member/member');
			$aSex = $oSex->getFieldById($this->member['member_id']);

			$this->pagedata['member'] = $this->member;
			$this->pagedata['sex'] = $aSex['sex'];
			$this->pagedata['cpmenu'] = $this->map;
			$this->pagedata['current'] = $this->_action;
			$this->pagedata['_PAGE_']=$this->pagedata['_PAGE_']?'member/'.$this->pagedata['_PAGE_']:'member/'.$this->_tmpl;
			$this->pagedata['_MAIN_'] = 'member/main.html';

			if ('orderdetail' == $this->_action) {
				$this->pagedata['_PAGE_'] = dirname(__FILE__).'/view/shop/member/orderdetail.html';
			}
			parent::output();
		}

		function orderdetail($order_id)
		{
			$objOrder = &$this->system->loadModel('trading/order');
			$aOrder = $objOrder->load($order_id);
			$this->_verifyMember($aOrder['member_id']);
			$logs = $objOrder->getLogs($order_id);

			$this->pagedata['orderlogs'] = $objOrder->alterOrderLog($logs);

			if(!$aOrder||$this->member['member_id']!=$aOrder['member_id']){
				$this->system->error(404);
				exit;
			}
			if($aOrder['member_id']){
				$member = &$this->system->loadModel('member/member');
				$aMember = $member->getFieldById($aOrder['member_id'], array('email'));
				$aOrder['receiver']['email'] = $aMember['email'];
			}
			 if ($aOrder['pay_extend']){
				$payment=$this->system->loadModel('trading/payment');
				$aOrder['extendCon'] = $payment->getExtendCon($aOrder['pay_extend'],$aOrder['payment']);
			}
			$this->pagedata['order'] = $aOrder;

			$gItems = $objOrder->getItemList($order_id);
			foreach($gItems as $key => $item){
				$gItems[$key]['addon'] = unserialize($item['addon']);
				if($item['minfo'] && unserialize($item['minfo'])){
					$gItems[$key]['minfo'] = unserialize($item['minfo']);
				}else{
					$gItems[$key]['minfo'] = array();
				}
			}
			$this->pagedata['order']['items'] = $gItems;
			$this->pagedata['order']['giftItems'] = $objOrder->getGiftItemList($order_id);

			$oMsg = &$this->system->loadModel('resources/message');
			$orderMsg = $oMsg->getOrderMessage($order_id);
			$this->pagedata['ordermsg'] = $orderMsg;
			/* alone add start */
			$objCollocOrder = &$this->system->loadModel('plugins/collocate_goods/collocOrder');
			$aCoItems = $objCollocOrder->getCollocItemList($order_id);
			if (!empty($aCoItems) && is_array($aCoItems))
			{
				foreach ($aCoItems as $k => $v)
				{
					//主商品p_id为0 主商品的co_id和搭配商品的p_id是相同的
					if ('0' == $v['p_id'])
					{
						$coGoods[$v['co_id']]['goods'] = $v;
						$coGoods[$v['co_id']]['goods']['loopKey'] = 'co'.$k;
					}
					else
					{
						$coGoods[$v['p_id']]['items']['co'.$k] = $v;
					}
				}

				$this->pagedata['showColloc'] = true;
				$this->pagedata['collocGoods'] = &$coGoods;
			}
			$this->pagedata['orderinfo_path'] = dirname(__FILE__).'/view/shop/common/orderinfo.html';
			/* alone add end */
			$this->_output();
		}
	}

?>